package MovieDBServer;

import com.cooper.java.scraper.DownloadException;
import com.cooper.java.scraper.DownloadParams;
import com.cooper.java.scraper.HttpDownload;
import com.cooper.java.scraper.ScraperException;
import com.cooper.moviedb.servers.FlvcdMovieCollection;
import com.cooper.moviedb.servers.MovieOut;
import com.cooper.moviedb.servers.ServicesDao;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.regex.Pattern;

/**
 * Hello world!
 */
public class App {
    public static void main(String[] args) {


        ApplicationContext context = new ClassPathXmlApplicationContext("*spring-config.xml");



        /*
        FlvcdMovieCollection collection = (FlvcdMovieCollection) context.getBean("flvcdMovieCollect");
        collection.init("/home/cooperlee/flvcd_movie.xml");
        try {
            //collection.generatePages();
            collection.generatePage(130);
           // collection.generateSinglePage(10);
            collection.collection();
        } catch (Exception e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
         */




      MovieOut out = (MovieOut) context.getBean("movieOut");
      out.updateOutPages("/home/cooperlee/testxml/","http://cooper-media-database.googlecode.com/svn/plug/MOVIE_DB/BROWSE_ALL/");
       //out.initOutPages("/home/cooperlee/testxml/","http://cooper-media-database.googlecode.com/svn/plug/MOVIE_DB/BROWSE_ALL/");
      // out.addDeleteMedia("http://v.pptv.com/show/EIh181vBMWicSUJw.html");

     // out.addUrl("flvcd_dy_dy74364.htm","http://www.funshion.com/subject/play/87899/2");

        /*
       HttpDownload httpDownload = new HttpDownload(new DownloadParams());
        try {
            System.out.println("" + httpDownload.urlExists("http://www.m1905.com/vod/countdown/597853.shtml"));

            String page = httpDownload.downloadPage("http://www.m1905.com/vod/countdown/597853.shtml");
            if (page != null) {
                System.out.println(page);
                if (Pattern.compile("<p class=\"time_text\">距[^<]*<span[^>]*><a[^>]*>.*</a></span>.*?免费点播时间还有</p>").matcher(page).find()) {
                    System.out.println("TODOU is FALSE");
                }
            }
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (DownloadException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
         */

       // Timestamp nowTimestamp = new Timestamp(new Date().getTime());
       // System.out.println(new Date(nowTimestamp.getTime()));
       // System.out.println(new Date(2012 - 1900,12 - 1,25));

      //  System.out.println((nowTimestamp.getTime() - new Date(2012 - 1900,12 - 1,25).getTime()) / 1000 / 60 /60 /24);

    }
}
